﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static AccountOperations.AccountOperations;

namespace Bank_database_system.业务部.账户操作
{
    public partial class 修改用户信息b : UserControl
    {
        public event EventHandler ButtonBack;
        public 修改用户信息b()
        {
            InitializeComponent();
        }

        public void Information_Set(string ID)
        {
            //传入信息
            DataTable dataTable = CustomerInquiryByID(ID);
            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                DataRow row = dataTable.Rows[0];
                string name = row["NAME"].ToString();
                string address = row["ADDRESS"].ToString();
                string phone = row["PHONENUMBER"].ToString();

                textBox4.Text = name;
                textBox2.Text = address;
                textBox3.Text = phone;
                textBox1.Text = ID;
                textBox1.Enabled = false;
            }
            else
            {
                MessageBox.Show("查询失败，请稍后再试！");
                ButtonBack?.Invoke(this, EventArgs.Empty);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            ButtonBack?.Invoke(this, EventArgs.Empty);
        }
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (textBox1.TextLength == 18)
            {
                if (e.KeyChar != '\b')
                    e.Handled = true;
            }
            else
            {
                if ((e.KeyChar > '9' || e.KeyChar < '0') && e.KeyChar != '\b' && e.KeyChar != 'X' && e.KeyChar != 'x')
                    e.Handled = true;
            }
        }
        private void button9_Click(object sender, EventArgs e)
        {
            //身份证（等信息）判断
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
            {
                MessageBox.Show("信息栏不能为空！");
                return;
            }

            if (CustomerUpdate(textBox1.Text, textBox4.Text, textBox2.Text, textBox3.Text))
            {
                MessageBox.Show("信息修改完成！");
                button3_Click(this, e);
            }
            else
            {
                MessageBox.Show("更新失败，请稍后再试！");
            }
        }
    }
}
